package leetcode;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2571.java
 * @Author : WangRuoyu
 * @Date 2023/2/23 10:36
 */
public class Q2571 {
    public int minOperations(int n) {
        int a = 0;
        int b = 0;

        while (n != 0) {
            if (n % 2 == 0) {
                a++;
            } else {
                b++;
            }
            n /= 2;
        }

        return Math.min(a + 2, b);
    }

    public static void main(String[] args) {
        Q2571 sl = new Q2571();
        int n = 39;
        System.out.println(sl.minOperations(n));
    }
}